package com.fcscs.cservice.communication;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.fcscs.cservice.common.CServiceCommonEnums;
import com.fcscs.cservice.communication.CommIntfAdaptor.CommParam;
import com.fcscs.cservice.ws.client.communicationservice.SendDataClient;
import com.fcscs.ws.schemas.communicationservice.SendDataRequest;
import com.fcscs.ws.schemas.communicationservice.SendDataResponse;

public class RemoteOutboundHandler implements OutboundHandler {
	@Autowired
	SendDataClient cln;

	@Override
	public byte[] sendBytes(String ip, CServiceCommonEnums.CommAdaptorEnum commAdaptor, String destination, byte[] data, Map<CommParam, Serializable> params) {
		SendDataRequest req = new SendDataRequest();
		req.setData(new String(data));
		req.setCommType(commAdaptor.toString());
		ArrayList<SendDataRequest.Parameter> paramList = new ArrayList<SendDataRequest.Parameter>();
		for (CommParam p : params.keySet()) {
			SendDataRequest.Parameter param = new SendDataRequest.Parameter();
			param.setName(p.toString());
			param.setValue(params.get(p).toString());
			paramList.add(param);
		}
		req.setParams(paramList);
		SendDataResponse resp = cln.sendData(ip, req);
		if (resp.getSuccess()) {
			return data;
		} else {
			return null;
		}
	}
}
